<html>
<head>
     <meta charset='UTF-8'>
     <meta http-equiv="Access-Control-Allow-Origin" content="*" />
     <title>socket.io客户端</title>
     <script src='http://127.0.0.1:3038/socket.io/socket.io.js'></script>
</head>
<body>
     <button id='send'>发送消息到服务器</button>
     <button id="login">登陆</button>
     <button id="pipei">匹配</button>
     <div>
          <h3>服务器响应的消息：</h3>
          <i id='msg'></i>
     </div>

     <script>
          var socket = io('ws://127.0.0.1:3038');
          var send = document.querySelector('#send');
          var msg = document.querySelector('#msg');
          var login = document.querySelector('#login');
          var pipei = document.querySelector('#pipei');

          // 登陆
          login.onclick = function(){
               socket.emit('login',Math.random());
          }
          // 匹配
          pipei.onclick = function(){
               socket.emit('play',"开局")
               socket.on('fapai',data=>{
                    console.log(data,"牌");
               })
          }

          socket.on('getMsg', data => {
              console.log('服务端消息：',  data);
              msg.innerHTML = `${data} <br/>`;
          })

          // socket.emit('send', 'hello');
          send.onclick = () => {
               console.log('点击了发送消息！');
               socket.emit('send', 'hello');
          }
     </script>
</body>
</html>